//
//  libNetworkActivityIndicator.m
//  lib
//

//

#import "libNetworkActivityIndicator.h"


static libNetworkActivityIndicator* gInstance = nil;




@implementation libNetworkActivityIndicator


- (id)init
{
	if( self = [super init] )
	{
		m_visible = NO;
		m_count = 0;
	}
	return self;
}


- (void)setVisible:(BOOL)visible
{
	if( visible )
	{
		if( !m_count && !m_visible )
		{
			UIApplication* app = [UIApplication sharedApplication];
			app.networkActivityIndicatorVisible = YES;
		}
		m_count++;
	}
	else 
	{
		if( m_count )
		{
			m_count--;
		}
		if( !m_count && !m_visible )
		{
			UIApplication* app = [UIApplication sharedApplication];
			app.networkActivityIndicatorVisible = NO;
		}
	}
}

- (void)resetVisible
{
	m_count = 0;
	if( !m_visible )
	{
		UIApplication* app = [UIApplication sharedApplication];
		app.networkActivityIndicatorVisible = NO;
	}
}


- (void)ON
{
	if( !m_visible )
	{
		m_visible = YES;
		UIApplication* app = [UIApplication sharedApplication];
		app.networkActivityIndicatorVisible = m_visible;
	}
}


- (void)OFF
{
	if( m_visible )
	{
		m_visible = NO;
		UIApplication* app = [UIApplication sharedApplication];
		app.networkActivityIndicatorVisible = m_visible;
	}
}


+ (libNetworkActivityIndicator *)Shared
{
	if( !gInstance )
	{
		gInstance = [[libNetworkActivityIndicator alloc] init];
	}
	return gInstance;
}
@end
